@isTest
public class TestItemTrigger {

    public static List<Item_Group__c> insertTestItemGroups() {
    	List<Item_Group__c> itemGroups = new List<Item_Group__c>();
        Item_Group__c itg1 = new Item_Group__c(Name='item group1', Description__c='Desc1', Total_Inventory__c=0);
        itemGroups.add(itg1);
        Item_Group__c itg2 = new Item_Group__c(Name='item group2', Description__c='Desc2', Total_Inventory__c=0);
        itemGroups.add(itg2);
        Item_Group__c itg3 = new Item_Group__c(Name='item group3', Description__c='Desc3', Total_Inventory__c=0);
        itemGroups.add(itg3);
        Item_Group__c itg4 = new Item_Group__c(Name='item group4', Description__c='Desc4', Total_Inventory__c=0);
        itemGroups.add(itg4);
        insert itemGroups;
        return itemGroups;
    }
    public static List<Item__c> insertTestItems(List<Item_Group__c> itemGroups)
    {
    	List<Item__c> items = new List<Item__c>();
    	Item__c itm1 = new Item__c(Item_Group__c=itemGroups[0].id,Brand_Name__c='b1',Cartridge_Colour__c='c1',Description__c='c2',Serial_Number__c='c31',Version__c='c4');
    	items.add(itm1);
    	Item__c itm2 = new Item__c(Item_Group__c=itemGroups[0].id,Brand_Name__c='b1',Cartridge_Colour__c='c1',Description__c='c2',Serial_Number__c='c32',Version__c='c4');
    	items.add(itm2);
    	Item__c itm3 = new Item__c(Item_Group__c=itemGroups[1].id,Brand_Name__c='b1',Cartridge_Colour__c='c1',Description__c='c2',Serial_Number__c='c33',Version__c='c4');
    	items.add(itm3);
    	Item__c itm4 = new Item__c(Item_Group__c=itemGroups[1].id,Brand_Name__c='b1',Cartridge_Colour__c='c1',Description__c='c2',Serial_Number__c='c34',Version__c='c4');
    	items.add(itm4);
    	Item__c itm5 = new Item__c(Item_Group__c=itemGroups[2].id,Brand_Name__c='b1',Cartridge_Colour__c='c1',Description__c='c2',Serial_Number__c='c35',Version__c='c4');
    	items.add(itm5);
    	Item__c itm6 = new Item__c(Item_Group__c=itemGroups[2].id,Brand_Name__c='b1',Cartridge_Colour__c='c1',Description__c='c2',Serial_Number__c='c36',Version__c='c4');
    	items.add(itm6);
    	Item__c itm7 = new Item__c(Item_Group__c=itemGroups[3].id,Brand_Name__c='b1',Cartridge_Colour__c='c1',Description__c='c2',Serial_Number__c='c37',Version__c='c4');
    	items.add(itm7);
    	Item__c itm8 = new Item__c(Item_Group__c=itemGroups[3].id,Brand_Name__c='b1',Cartridge_Colour__c='c1',Description__c='c2',Serial_Number__c='c38',Version__c='c4');
    	items.add(itm8);
    	insert items;
    	return items;
    }
    
    public static List<Certificate_Data__c> insertCertData(List<Item__c> items)
    {
    	List<Certificate_Data__c> certData = new List<Certificate_Data__c> ();
    	Certificate_Data__c certd1 = new Certificate_Data__c(Name='cert1',Expiry_date__c=Date.newInstance(2013, 2, 1),Test_Date__c=Date.newInstance(2012, 3, 1),Pass__c=true,Item__c=items[0].Id);
    	certData.add(certd1);
    	Certificate_Data__c certd2 = new Certificate_Data__c(Name='cert2',Expiry_date__c=Date.newInstance(2013, 2, 1),Test_Date__c=Date.newInstance(2012, 3, 1),Pass__c=true,Item__c=items[1].Id);
    	certData.add(certd2);
    	Certificate_Data__c certd3 = new Certificate_Data__c(Name='cert3',Expiry_date__c=Date.newInstance(2013, 2, 1),Test_Date__c=Date.newInstance(2012, 3, 1),Pass__c=true,Item__c=items[2].Id);
    	certData.add(certd3);
    	Certificate_Data__c certd4 = new Certificate_Data__c(Name='cert4',Expiry_date__c=Date.newInstance(2013, 2, 1),Test_Date__c=Date.newInstance(2012, 3, 1),Pass__c=true,Item__c=items[3].Id);
    	certData.add(certd4);
    	Certificate_Data__c certd5 = new Certificate_Data__c(Name='cert5',Expiry_date__c=Date.newInstance(2013, 2, 1),Test_Date__c=Date.newInstance(2012, 3, 1),Pass__c=true,Item__c=items[4].Id);
    	certData.add(certd5);
    	insert certData;
    	return certData;
    }
    
    public static List<Item_Group_Approver__c> insertTestItemGroupApprovers(List<Item_Group__c> itemGroups)
    {
        List<Item_Group_Approver__c> itmGrpApprovers = new List<Item_Group_Approver__c>();
        Item_Group_Approver__c itmGrpApprover1 = new Item_Group_Approver__c(name='IGP1',Item_Group__c=itemGroups[0].id,User__c=UserInfo.getUserId());
        itmGrpApprovers.add(itmGrpApprover1);
        Item_Group_Approver__c itmGrpApprover2 = new Item_Group_Approver__c(name='IGP2',Item_Group__c=itemGroups[1].id,User__c=UserInfo.getUserId());
        itmGrpApprovers.add(itmGrpApprover2);
        insert itmGrpApprovers;
        return itmGrpApprovers;
    }
    @isTest 
    static void test_ItemTrigger() 
   {
   		Test.startTest();
   		List<Item_Group__c> itmGrps = insertTestItemGroups();
   		insertTestItemGroupApprovers(itmGrps);
   		List<Item__c> itms = insertTestItems(itmGrps);
   		delete itms[0];
   		Test.stopTest();
   }
}